﻿using Api.Shared.Model.Web.Login;
using Api.Shared.Sugar;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;

namespace Api.Shared.Responsitory.Sqlite
{
    public class SqliteRespository<TEntity> : SimpleClient<TEntity> where TEntity : class, new()
    {
        //where TEntity : new()：这个约束指定 TEntity 必须有一个公共的无参数构造函数
        public SqliteRespository([FromKeyedServices(nameof(SqlName.sqlite))] ISugarClientService service)
        {
            Context = service.Db;
        }

        /// <summary>
        /// 扩展方法，自带方法不能满足的时候可以添加新方法
        /// </summary>
        /// <returns></returns>
        public IEnumerable<TEntity> CommQuery(string json)
        {
            //base.Context.Queryable<T>().ToList();可以拿到SqlSugarClient 做复杂操作
            return null;
        }

        public RolesItemNew FindRolesItemNewById(int rolesItemNewId)
        {
            return Context.Queryable<RolesItemNew>().Where(x => x.id == rolesItemNewId).First();
        }

        public List<MenuItemNew>? QueryLevelOne()
        {
            return Context.Queryable<MenuItemNew>().Where(x => x.level == 1).ToList();
        }

        public List<MenuItemNew>? QueryLevelTwo()
        {
            return Context.Queryable<MenuItemNew>().Where(x => x.level == 2).ToList();
        }

        public List<MenuItemNew>? QueryLevelThree()
        {
            return Context.Queryable<MenuItemNew>().Where(x => x.level == 3).ToList();
        }
    }
}
